Dart.PowerTCP.SslSockets Namespace > Udp Class > Send Method : Send(Byte[],String,Int32) Method |
Send a datagram to the specified remote address and port.
[Visual Basic]
<DescriptionAttribute("Send a datagram from your buffer.")>
Overloads Public Function Send( _
ByVal buffer() As Byte, _
ByVal host As String, _
ByVal port As Integer _
) As Datagram
[C#]
[DescriptionAttribute("Send a datagram from your buffer.")]
public Datagram Send(
byte[] buffer,
string host,
int port
);
[C++]
[DescriptionAttribute("Send a datagram from your buffer.")]
public: Datagram* Send(
byte[]* buffer,
string* host,
int port
)
[C++/CLI]
[DescriptionAttribute("Send a datagram from your buffer.")]
public:
Datagram^ Send(
bytearray<buffer>^ buffer,
String^ host,
int port
)
A Datagram object encapsulating the datagram sent.
Exception | Description |
---|---|
ArgumentNullException | buffer is null. |
SocketException | The remote address is unknown, invalid, or unable to be resolved. |
ArgumentOutOfRangeException | The remote port is out of the range of valid values. |
Use the Udp.Send method to sent a datagram created from the data contained in buffer to the specified host and port.
A UDP datagram provides little functionality over an IP datagram, adding a port number field which allows multiplexing on the receiving host and checksum field which provides basic error handling. Unlike TCP, UDP datagrams are sent as a unit. If Udp.Send is called 3 times to send 3 datagrams to a host, the receiving host will have to call Receive 3 times. Also, the size of each datagram sent will equal the size of each datagram received by the receiving host. In addition, since UDP is a connectionless protocol, any datagrams sent to the host are not guaranteed to be delivered. Therefore, any required error checking (outside of UDP's checksum implementation) will have to be done by the application-layer protocol.
To send a broadcast datagram, use "255.255.255.255" as the remote address. To sent a multicast datagram, use the multicast group address as the remote address after first joining a multicast group by using Udp.JoinMulitcastGroup.
The following example demonstrates sending some datagrams to an echo server and receiving the datagrams from the echo server.
[Visual Basic]
Dim iterations as Integer = 3
' Listen on the default interface and an ephemeral port.
udp1.Open()
' Send several datagrams
Dim buffer As Byte() = System.Text.Encoding.Default.GetBytes("test")
Dim i as Integer
For(i=0; i<iterations; i++)
Udp1.send(buffer, "MyEchoServer", 7)
Next
' receive the echoed datagrams, there should be 3...requiring 3 Udp.Receive calls.
For(i=0; i<iterations; i++)
Dim d as Datagram = Udp1.Receive(buffer.Length)
Debug.WriteLine(d.ToString())
Next
'* Output
'* ------------------------
'* test
'* test
'* test
'* ------------------------
'*
[C#]
int iterations = 3;
// Listen on the default interface and an ephemeral port.
udp1.Open();
// Send several datagrams
byte[] buffer =
System.Text.Encoding.Default.GetBytes("test");
for(int i=0; i<iterations; i++)
udp1.send(buffer, "MyEchoServer", 7);
// receive the echoed datagrams, there should be 3...requiring 3 Udp.Receive calls.
for(int i=0; i<iterations; i++)
{
Datagram d = udp1.Receive(buffer.Length);
Debug.WriteLine(d.ToString());
}
/* Output
* ------------------------
* test
* test
* test
* ------------------------
*/
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Udp Class | Udp Members | Overload List
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.